//
//  TaiZhangmanagerCell.m
//  YunGui
//
//  Created by User on 16/4/14.
//  Copyright © 2016年 hanen. All rights reserved.
//

#import "TaiZhangmanagerCell.h"
#import "Macro.h"
#import "TaiZhangModel.h"

#define Height(msg) [UIView getHeight:msg]
#define Width(msg) [UIView getWidth:msg]
@interface TaiZhangmanagerCell ()
{
    CGFloat   space;

    UILabel *_officeLabel;
    UILabel *_addressLabel;
    UILabel *_signLabel;
    UILabel *_InstallLabel;
    UILabel *_startLabel;
    UILabel *_payLabel;
    UILabel *_packageLabel;
    UILabel *_useLabel;
    
}
@end
@implementation TaiZhangmanagerCell
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *TaiZhangCellid = @"TaiZhangCellid";
    TaiZhangmanagerCell *cell = [tableView dequeueReusableCellWithIdentifier:TaiZhangCellid];
    if (cell == nil) {
        cell = [[TaiZhangmanagerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TaiZhangCellid];
        //cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell addSubviews];
    }
    return cell;
}
- (void)addSubviews
{
    
    space = [UIView getWidth:10.0f];
    
    CGFloat cellH = [TaiZhangmanagerCell cellHeight];
    
    UIImageView  *quan = [[UIImageView alloc] initWithFrame:CGRectMake(Width(20),  Height(15), 10.0f, 10.0f)];
    quan.clipsToBounds = YES;
    quan.layer.cornerRadius = 5.0f;
    quan.image = [UIImage imageNamed:@"Btn_Normal_Biaoti"];
    [self.contentView addSubview:quan];
    UILabel *xianLab = [[UILabel alloc] initWithFrame:CGRectMake(quan.x, cellH - 1, kScreenWidth - 4*space, 1)];
    xianLab.backgroundColor = GrayLineColor;
    [self.contentView addSubview:xianLab];
    
    _officeLabel = [ViewTool getLabelWith:CGRectMake(quan.maxX+Width(5), Height(10), self.contentView.width - quan.maxX, 20.0f) WithTitle:@"" WithFontSize:15.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_officeLabel];
    
    _addressLabel = [ViewTool getLabelWith:CGRectMake(_officeLabel.x, _officeLabel.maxY + Height(5), kScreenWidth - quan.maxX, 20.0f) WithTitle:@"" WithFontSize:14.0f WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_addressLabel];

    _signLabel = [ViewTool getLabelWith:CGRectMake(_officeLabel.x, _addressLabel.maxY + Height(10), 6*space, 20.0f) WithTitle:@"" WithFontSize:20.0f WithTitleColor:UIColorFromRGB(0xff7701) WithTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:_signLabel];
    _InstallLabel = [ViewTool getLabelWith:CGRectMake(_signLabel.maxX+Width(40), _signLabel.y, 6*space, 20.0f) WithTitle:@"" WithFontSize:20.0f WithTitleColor:YELLOWCOLOR WithTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:_InstallLabel];
    _startLabel = [ViewTool getLabelWith:CGRectMake(_InstallLabel.maxX+Width(40), _signLabel.y, 6*space, 20.0f) WithTitle:@"" WithFontSize:20.0f WithTitleColor:BlueColor WithTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:_startLabel];
    
    UILabel *sign = [ViewTool getLabelWith:CGRectMake(_signLabel.x , _signLabel.maxY+Height(0.5), 6*space, 20.0f) WithTitle:@"签约数" WithFontSize:14.0f WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:sign];
    
    UILabel *install = [ViewTool getLabelWith:CGRectMake(_InstallLabel.x , _InstallLabel.maxY+Height(0.5), 6*space, 20.0f) WithTitle:@"安装数" WithFontSize:14.0f WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:install];
    
    UILabel *start = [ViewTool getLabelWith:CGRectMake(_startLabel.x , _startLabel.maxY+Height(0.5), 6*space, 20.0f) WithTitle:@"启用数" WithFontSize:14.0f WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:start];
 
    UILabel *pay = [ViewTool getLabelWith:CGRectMake(_signLabel.x-Width(10) , sign.maxY+Height(10), Width(57), 20.0f) WithTitle:@"收费数量:" WithFontSize:14.0f WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:pay];
    
    UILabel *package = [ViewTool getLabelWith:CGRectMake(_InstallLabel.x - Width(3) , pay.y, Width(45), 20.0f) WithTitle:@"包裹数:" WithFontSize:14.0f WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:package];
    
    UILabel *use = [ViewTool getLabelWith:CGRectMake(_startLabel.x - Width(10) , pay.y, Width(45), 20.0f) WithTitle:@"使用率:" WithFontSize:14.0f WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:use];
    
    _payLabel = [ViewTool getLabelWith:CGRectMake(pay.maxX, pay.y, Width(60), 20.0f) WithTitle:@"" WithFontSize:14.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_payLabel];
    _packageLabel = [ViewTool getLabelWith:CGRectMake(package.maxX, package.y, Width(60), 20.0f) WithTitle:@"" WithFontSize:14.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_packageLabel];
    _useLabel = [ViewTool getLabelWith:CGRectMake(use.maxX, use.y, Width(55), 20.0f) WithTitle:@"" WithFontSize:14.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_useLabel];

    UILabel *label1 =[[UILabel alloc] initWithFrame:CGRectMake(xianLab.x+xianLab.width/3.0, _signLabel.y+space, 1, 25)];
    label1.backgroundColor = GrayLineColor;
    [self.contentView addSubview:label1];
    
    UILabel *label2 =[[UILabel alloc] initWithFrame:CGRectMake(xianLab.x+2*xianLab.width/3.0, _signLabel.y+space, 1, 25)];
    label2.backgroundColor = GrayLineColor;
    [self.contentView addSubview:label2];
    
}
- (void)setModel:(TaiZhangModel *)model
{
    _model = model;
    _officeLabel.text = model.agency;
    NSString *str = [NSString string];
    if ([model.area intValue] == 0) {
        str = @"";
    }else if ([model.area intValue] == 1){
        str = @"北区/";
    }else if ([model.area intValue] == 2){
        str = @"南区/";
    }
    _addressLabel.text = [NSString stringWithFormat:@"%@%@/%@",str,model.city,model.province];
    
    _signLabel.text = [NSString stringWithFormat:@"%d",[model.sign_num intValue]];
    _InstallLabel.text = [NSString stringWithFormat:@"%d",[model.installed_num intValue]];
    _startLabel.text = [NSString stringWithFormat:@"%d",[model.enabled_num intValue]];
    _payLabel.text = [NSString stringWithFormat:@"%d",[model.pay_num intValue]];
    _packageLabel.text = [NSString stringWithFormat:@"%d",[model.express_num intValue]];
    _useLabel.text = model.usage;
    
}

+ (CGFloat)cellHeight
{
    return Height(45.5)+100;
}

@end
